package com.lc.util;

import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ReporterType;
import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.testng.annotations.*;
import java.io.IOException;
import java.util.Map;

/**
 * Created by lc on 2016/9/7.
 */
public class BaseClass {





    public  void befores(ExtentReports extent){
        String reportLocation = "report/ExtentReport.html";
        extent = new ExtentReports(reportLocation, true);
        extent.startReporter(ReporterType.DB, reportLocation);
        extent.addSystemInfo("Host Name", "Lining");
    }



	/*
	* 登录进入系统获取JSESSIONID放入到CookieStore中
	* */
    public  CookieStore LoginIn(String url ,String objBean, String statusCode,String xmlName,HttpUtils httpUtils,CookieStore cookieStore,CookieUtil cookieUtil) {
        Map<String,String> params=xmlUtil.readXMLDocument(objBean,xmlName);
        CloseableHttpClient client = HttpClients.createDefault();
        CloseableHttpResponse httpResponse= httpUtils.post(url, params, client, cookieStore);
        //cookieUtil.printResponse(httpResponse);
        return  cookieStore=cookieUtil.setCookieStore(httpResponse);


    }


    public void closeClient(CloseableHttpClient client){
        try {
            // 关闭流并释放资源
            client.close();
            System.out.println("AfterClass");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



    public  void afters(ExtentReports extent){

        extent.close();

    }




}
